package com.zhuang.singleton.type8;

/**
 * @Classname SingletonTest08
 * @Description  枚举的方式实现单例模式
 * @Date 2021/3/17 10:06
 * @Created by dell
 */

public class SingletonTest08 {
    public static void main(String[] args) {
        System.out.println("枚举的方式实现单例模式，推荐使用");
        Singleton instance = Singleton.INSTANCE;
        Singleton instance2 = Singleton.INSTANCE;
        System.out.println(instance == instance2);
        //判断是否为单例
        System.out.println(instance == instance2);
        System.out.println("intstance的哈希值" + instance.hashCode());
        System.out.println("intstance2的哈希值" + instance2.hashCode());
    }
}

/*
枚举
 */
enum Singleton {
    INSTANCE;//属性

    public void method() {
        System.out.println("method()方法被调用...");
    }
}
